package web.exercise.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import web.exercise.Dao.ContactsDao;
import web.exercise.Dao.impl.ContactsDaoImpl;
import web.exercise.entity.Contacts;

public class QueryContactsServlet extends HttpServlet {
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		response.setContentType("text/html; charset=utf-8");
		//通过传入的id找到指定的对象
		ContactsDao dao=new ContactsDaoImpl();
		Contacts contacts=dao.getContactsById(request.getParameter("id"));
		//将对象转发到jsp
		request.setAttribute("contacts", contacts);
		//请求转发
		request.getRequestDispatcher("modifyContacts.jsp").forward(request, response);
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doGet(request,response);
	}

}
